package main

import (
	"go/token"
	"go/ast"
)

type v struct{}

//nil .Doc, .Comment, .Comments
func (v v) Visit(n ast.Node) ast.Visitor {
	switch t := n.(type) {
	case *ast.Field:
		t.Doc = nil
		t.Comment = nil
	case *ast.File:
		t.Doc = nil
		t.Comments = []*ast.CommentGroup{}
	case *ast.FuncDecl:
		t.Doc = nil
	case *ast.GenDecl:
		t.Doc = nil
	case *ast.ImportSpec:
		t.Doc = nil
		t.Comment = nil
	case *ast.TypeSpec:
		t.Doc = nil
		t.Comment = nil
	case *ast.ValueSpec:
		t.Doc = nil
		t.Comment = nil
	}
	return v
}

//This fixes the AST so we can output file with go/printer without the comments
//interspersing in the middle of funcs and ruining all the output.
func Issue1505(fs *token.FileSet, file *ast.File) *ast.File {
	ast.Walk(v{}, file)
	return file
}
